import java.util.HashMap;

public class work1 {
    public int findMaxLength(int[] nums) {
        HashMap<Integer,Integer>map=new HashMap<>();
        int sum=0,ret=0;
        for(int i=0;i<nums.length;i++){
            sum+=nums[i]==1?1:-1;
            if(map.containsKey(sum))ret=Math.max(ret,i-map.get(sum));
            else map.put(sum,map.getOrDefault(sum,0));
        }
        return ret;
    }
}
